//Eg6-2.cpp
#include <iostream.h>
class Complex {
private:
		double  r, i;
public:
		Complex (double R=0, double I=0) : r(R), i(I){ };
		friend Complex operator+(Complex a,Complex b);
		friend Complex operator-(Complex a,Complex b);
		friend Complex operator*(Complex a,Complex b);
		friend Complex operator/(Complex a,Complex b);
		void  display();
};
Complex operator+(Complex a,Complex b)
{
	return Complex(a.r+b.r,a.i+b.i);
}
Complex operator-(Complex a,Complex b)
{
	return Complex(a.r-b.r,a.i-b.i);
}
Complex operator*(Complex a,Complex b)
{
	Complex t;
	t.r=a.r*b.r-a.i*b.i;
	t.i=a.r*b.i+a.i*b.r;
	return t;
}
Complex operator/(Complex a,Complex b) 
{
	Complex t;
	double x;
	x=1/(b.r*b.r+b.i*b.i);
	t.r=x*(a.r*b.r+a.i*b.i);
	t.i=x*(a.i*b.r-a.r*b.i);
	return t;
}
void Complex::display()
{
	cout<<r;
	if (i>0) cout<<"+";
	if (i!=0) cout<<i<<"i"<<endl;
}
void main(void)
{
	Complex c1(1,2),c2(3,4),c3,c4,c5,c6;
	c3=c1+c2;
	c4=c1-c2;
	c5=c1*c2;
	c6=c1/c2;
	c1.display();
	c2.display();
	c3.display();
	c4.display();
	c5.display();
	c6.display();
}
